<!DOCTYPE html>
<html>
<head>
    <!--hospital_purchase_catalog-->
	<meta charset="utf-8">
	<title>文章列表--layui后台管理模板 2.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="resources/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="resources/css/public.css" media="all" />
</head>
<body class="childrenBody">
<!--模糊查询-->
<div>
    <blockquote style="margin-right: 10%" class="layui-elem-quote quoteBox layui-col-lg-offset1">
        <form class="layui-form" id="searchTable" lay-filter="searchTable">
    	    <div class="layui-form-item layui-row">
    	        <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">药品流水号</label>
                	<div class="layui-input-block">
                		<input type="text" name="serialNumber" id="serialNumber" class="layui-input searchVal" />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">通用名</label>
                	<div class="layui-input-block">
                		<input type="text" name="commonName" id="commonName" class="layui-input searchVal" />
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">剂型</label>
                	<div class="layui-input-block">
                	    <input name="dosageForm" class="layui-input searchVal" id="dosageForm" />
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">规格</label>
                	<div class="layui-input-block">
                	    <input name="size" class="layui-input searchVal" id="size" >
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">单位</label>
                	<div class="layui-input-block">
                		<input type="text" name="unit" class="layui-input createTime">
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                	<label class="layui-form-label">转换系数</label>
                	<div class="layui-input-block">
                    	<input type="text" class="layui-input" name="factor" id="factor">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">生产企业</label>
                	<div class="layui-input-block">
                		<input type="text" name="productionName" class="layui-input searchVal"/>
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">商品名</label>
                	<div class="layui-input-block">
                		<input type="text" name="commodityName" class="layui-input searchVal"/>
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">价格范围</label>
                	<div class="layui-input-block">
                	    <input type="hidden" name="minPrice">
                	    <input type="hidden" name="maxPrice">
                		<div id="priceRange" class="demo-slider"></div>
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">药品类别</label>
                	<div class="layui-input-block">
                		<select name="drugCategory" id="drugCategory" lay-filter="drugCategory">
                            <option>请选择药品类别：</option>
                        </select>
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-row">
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">交易状态</label>
                	<div class="layui-input-block">
                		<select name="transaction" id="transaction" lay-filter="transaction">
                            <option>请选择交易状态：</option>
                        </select>
                	</div>
                </div>
                <div class="layui-inline layui-col-md5">
                    <label class="layui-form-label">供货状态</label>
                	<div class="layui-input-block">
                		<select name="controlState" id="controlState" lay-filter="controlState">
                            <option>请选择供货状态：</option>
                        </select>
                	</div>
                </div>
            </div>
            <div class="layui-form-item layui-center">
                <div class="layui-input-block">
                  <button type="submit" class="layui-btn" lay-submit="" lay-filter="search">查询</button>
                   <button type="button" class="layui-btn" lay-submit="" lay-filter="close">关闭</button>
                </div>
            </div>
    	</form>
    </blockquote>
</div>
<!--展示供应商和药品信息-->
<div style="display: none" id="showData" lay-filter="showData">
	<h2 style="margin-left: 10px">药品信息</h2>
	<form class="layui-form" id="showDataDrugForm" lay-filter="showDataDrugForm">
        <div class="layui-form-item">
	        <div class="layui-inline ">
                <label class="layui-form-label">药品名</label>
            	<div class="layui-input-inline">
            	    <input type="hidden" name="id">
            		<input type="text" name="commodityName" class="layui-input searchVal" readonly />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">药品流水号</label>
            	<div class="layui-input-inline">
            		<input type="text" name="serialNumber" class="layui-input searchVal" readonly />
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline ">
                <label class="layui-form-label">药品通用名</label>
            	<div class="layui-input-inline">
            	    <input name="commonName" class="layui-input searchVal" readonly />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">批准文号</label>
            	<div class="layui-input-inline">
            		<input type="text" name="approvalNumber" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline ">
                <label class="layui-form-label">剂型</label>
            	<div class="layui-input-inline">
            		<input type="text" name="dosageForm" class="layui-input" readonly>
            	</div>
            </div>
            <div class="layui-inline ">
            	<label class="layui-form-label">规格</label>
            	<div class="layui-input-inline">
                	<input type="text" class="layui-input" name="size" readonly>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline ">
                <label class="layui-form-label">单位</label>
            	<div class="layui-input-inline">
            		<input type="text" name="unit" readonly class="layui-input searchVal"/>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">转换系数</label>
            	<div class="layui-input-inline">
            		<input type="text" name="factor" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">质量层次</label>
            	<div class="layui-input-inline">
            	    <input type="text" name="quality" id="layerQuality" readonly class="layui-input searchVal" placeholder="yyyy-MM-dd" />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">生产企业</label>
            	<div class="layui-input-inline">
            		<input type="text" name="productionName" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">药品类别</label>
            	<div class="layui-input-inline">
            	    <input type="text" name="drugCategory" id="layerDrugCategory" readonly class="layui-input searchVal"/>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">通用名拼音</label>
            	<div class="layui-input-inline">
            		<input type="text" name="commodityPinyin" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">批准文号有效期</label>
            	<div class="layui-input-inline">
            	    <input type="text" name="approvalDate" readonly class="layui-input searchVal"/>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">是否是进口药</label>
            	<div class="layui-input-inline">
            		<input type="text" name="isImport" id="layerIsImport" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">包装材质</label>
            	<div class="layui-input-inline">
            	    <input type="text" name="packages" readonly class="layui-input searchVal"/>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">包装单位</label>
            	<div class="layui-input-inline">
            		<input type="text" name="packageUnit" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">最新零售价</label>
            	<div class="layui-input-inline">
            	    <input type="text" name="newPrice" readonly class="layui-input searchVal"/>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">零售价出处</label>
            	<div class="layui-input-inline">
            		<input type="text" name="priceSource" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">质量层次说明</label>
            	<div class="layui-input-inline">
            	    <input type="text" name="qualityDescription" readonly class="layui-input searchVal"/>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">有无质检报告</label>
            	<div class="layui-input-inline">
            		<input type="text" name="haveReport" id="layerHaveReport" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">质检报告编号</label>
            	<div class="layui-input-inline">
            	    <input type="text" name="reportNum" readonly class="layui-input searchVal"/>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">质检报告有效期</label>
            	<div class="layui-input-inline">
            		<input type="text" name="reportDate" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">产品说明</label>
            	<div class="layui-input-inline">
            	    <input type="text" name="productionDescription" readonly class="layui-input searchVal"/>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">药品状态</label>
            	<div class="layui-input-inline">
            		<input type="text" name="transaction" id="layerTransaction" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">质量层次说明</label>
            	<div class="layui-input-inline">
            	    <input type="text" name="qualityDescription" readonly class="layui-input searchVal"/>
            	</div>
            </div>
        </div>
    </form>
    <h2 style="margin-left: 10px">供应商详情</h2>
    <form class="layui-form" id="showDataProviderForm" lay-filter="showDataProviderForm">
        <div class="layui-form-item">
            <div class="layui-inline ">
                <label class="layui-form-label">企业名称</label>
            	<div class="layui-input-inline">
            		<input type="text" name="providerName" readonly class="layui-input searchVal"/>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">企业类别</label>
            	<div class="layui-input-inline">
            		<input type="text" name="providerCategory" readonly class="layui-input searchVal" />
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline ">
                <label class="layui-form-label">许可证</label>
            	<div class="layui-input-inline">
            		<input type="text" name="licence" readonly class="layui-input searchVal"/>
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">许可证到期时间</label>
            	<div class="layui-input-inline">
            		<input type="text" name="licenceDeadline" readonly class="layui-input searchVal">
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">企业联系人</label>
            	<div class="layui-input-inline">
            		<input type="text" name="providerLinkman" readonly class="layui-input searchVal" />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">企业联系电话</label>
            	<div class="layui-input-inline">
            		<input type="text" name="providerPhone" readonly class="layui-input searchVal">
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">营业范围</label>
            	<div class="layui-input-inline">
            		<input type="text" name="businessScope" readonly class="layui-input searchVal" />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">注册地址</label>
            	<div class="layui-input-inline">
            		<input type="text" name="registeredAddress" readonly class="layui-input searchVal">
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">联系地址</label>
            	<div class="layui-input-inline">
            		<input type="text" name="contactAddress" readonly class="layui-input searchVal" />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">邮政编码</label>
            	<div class="layui-input-inline">
            		<input type="text" name="postalCode" readonly class="layui-input searchVal">
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">总资产</label>
            	<div class="layui-input-inline">
            		<input type="text" name="totalAssets" readonly class="layui-input searchVal" />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">企业传真</label>
            	<div class="layui-input-inline">
            		<input type="text" name="providerFax" readonly class="layui-input searchVal">
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">法人代表</label>
            	<div class="layui-input-inline">
            		<input type="text" name="corporateRepresentative" readonly class="layui-input searchVal" />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">法人身份证</label>
            	<div class="layui-input-inline">
            		<input type="text" name="corporataNumber" readonly class="layui-input searchVal">
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">企业注册资金</label>
            	<div class="layui-input-inline">
            		<input type="text" name="registeredCapital" readonly class="layui-input searchVal" />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">上年度销售金额</label>
            	<div class="layui-input-inline">
            		<input type="text" name="annualSalesAmount" readonly class="layui-input searchVal">
            	</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">电子信箱</label>
            	<div class="layui-input-inline">
            		<input type="text" name="email" readonly class="layui-input searchVal" />
            	</div>
            </div>
            <div class="layui-inline ">
                <label class="layui-form-label">网址</label>
            	<div class="layui-input-inline">
            		<input type="text" name="url" readonly class="layui-input searchVal">
            	</div>
            </div>
        </div>
	</form>
</div>
<!--数据表格-->
<div>
    <table class="layui-hide" id="drugMessageTable" lay-filter="drugMessageTable"></table>
    <div id="toolBars" style="display: none">
        <button type="button" lay-event="add" class="layui-btn layui-btn-sm"><span class="layui-icon layui-icon-add-1"></span>添加采购药品</button>
    </div>
    <div id="rowBars" style="display: none">
        <button type="button" lay-event="show" class="layui-btn layui-btn-sm layui-btn-warm"><span class="layui-icon layui-icon-search"></span>查看</button>
    </div>
</div>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script>
    layui.use(['form','jquery','layer','laydate','element','table','slider'],function() {
        var form = layui.form;
        var laydate = layui.laydate;
        var layer = layui.layer;
        var $ = layui.jquery;
        var table = layui.table;
        var slider = layui.slider;
        //滑块渲染
        var sliderIns = slider.render({
            elem: '#priceRange'
            ,min:0
            ,max:1000
            ,value: [0, 1000] //初始值
            ,range: true //范围选择
            ,change: function(vals){
                $('input[name="minPrice"]').val(vals[0]);
                $('input[name="maxPrice"]').val(vals[1]);
            }
        });
        //获取传过来的供应商id
        var id = window.location.href.split("id=")[1];
        if(id.indexOf("&")!=-1){
            id = id.split("&")[0];
        }
        //传过来的药品信息Id，用来筛选已经添加过的药品
        var drugMessageIds = window.location.href.split("drugMessageIds=")[1];
        if(drugMessageIds.indexOf("&")!=-1){
            drugMessageIds = drugMessageIds.split("&")[0];
        }
        //获取医院Id
        var hospitalId = window.location.href.split("hospitalId=")[1];
        if(hospitalId.indexOf("&")!=-1){
            hospitalId = hospitalId.split("&")[0];
        }
        //数据表格渲染
        var tableIns = table.render({
            elem:"#drugMessageTable",
            url:"/hospitalPurchaseCatalog/getAvaCatalog",
            where:{drugMessageIds:drugMessageIds,hospitalId:hospitalId},
            toolbar:"#toolBars",
            page:true,
            id:'drugMessageTableId',
            height:'470',
            cols:[
                [
                    {field:'id', title:'ID',  fixed: 'left', unresize: true,width:'80' ,sort: true,align:'center'}
                    ,{type:'checkbox',fixed:'center'}
                    ,{field:'drugMessage.serialNumber', title:'流水号',align:'center',width:'180',templet:function(res) {
                        return res.drugMessage.serialNumber;
                    }}
                    ,{field:'drugMessage.commonName', title:'通用名',align:'center',width:'180',templet:function (res) {
                        return res.drugMessage.commonName;
                     }}
                    ,{field:'drugMessage.dosageForm', title:'剂型',align:'center',width:'180',templet:function(res) {
                        return res.drugMessage.dosageForm;
                    }}
                    ,{field:'drugMessage.size', title:'规格',align:'center',width:'180',templet:function(res) {
                        return res.drugMessage.size;
                    }}
                    ,{field:'drugMessage.unit', title:'单位',align:'center',width:'180',templet:function(res) {
                        return res.drugMessage.unit;
                    }}
                    ,{field:'drugMessage.factor', title:'转换系数',align:'center',width:'180',templet:function (res) {
                        return res.drugMessage.factor;
                     }}
                    ,{field:'drugMessage.productionName', title:'生产企业',align:'center',width:'180',templet:function(res) {
                        return res.drugMessage.productionName;
                    }}
                    ,{field:'drugMessage.commodityName', title:'商品名',align:'center',width:'180',templet:function(res) {
                        return res.drugMessage.commodityName;
                    }}
                    ,{field:'drugMessage.winPrice', title:'中标价',align:'center',width:'180',templet:function(res) {
                        return res.drugMessage.winPrice;
                    }}
                    ,{field:'drugMessage.drugCategory', title:'药品类别',align:'center',width:'180',templet:function(res) {
                        var result = "";
                        $.ajax({
                            url:'/getDrugCategoryById',
                            type:'get',
                            data:{drugCategoryId:res.drugMessage.drugCategory},
                            async:false,
                            success:function(d) {
                                result = d.category;
                            }
                        })
                        return result;
                    }}
                    ,{field:'drugMessage.transaction', title:'交易状态',align:'center',width:'180',templet:function(res) {
                        return res.drugMessage.transaction==1?"正常":
                        res.drugMessage.transaction==2?"取消交易":"";
                    }}
                    ,{field:'provider.providerName', title:'供应商',align:'center',width:'180',templet:function(res) {
                        return res.provider.providerName;
                    }}
                    ,{field:'providerDrugCatalogControl.controlState', title:'供货状态',align:'center',width:'180',templet:function (d) {
                        return d.providerDrugCatalogControl==null?"":
                        d.providerDrugCatalogControl.controlState==1?"正常":
                        d.providerDrugCatalogControl.controlState==2?"暂停":"";
                     }}
                    ,{fixed: 'right', title:'操作', toolbar: '#rowBars',width:100}
                ]
            ]
        });
        //表单提交，查询
        form.on('submit(search)',function(data) {
            tableIns.reload({
                where:data.field
            })
            return false;
        });
        //关闭，返回到采购单维护
        form.on('submit(close)',function(data) {
            //获取采购单Id
            window.history.back();
            return false;
        });
        //监听头部工具栏事件
        table.on('toolbar(drugMessageTable)',function(obj) {
            switch (obj.event) {
                case 'add':
                    openAdd();
                    break;
            }
        });
        //监听行工具栏
        table.on('tool(drugMessageTable)',function(obj){
            switch (obj.event) {
                case 'show':
                    openShow(obj.data);
            }
        });
        //加载药品
        selectDrugCategory($("#drugCategory"),"/getDrugCategory");
        //交易状态
        select($("#transaction"),"/getDataDictionary?dateType=1");
        //供货状态
        select($("#controlState"),"/getDataDictionary?dateType=8");
        //药品供应商信息展示
        var mainIns;
        function openShow(data) {
            console.log(data);
            mainIns = layer.open({
                type:1,
                content:$("#showData"),
                area:['800px','630px'],
                title:"查看详情",
                success:function(layero,index) {
                    form.val("showDataDrugForm",data.drugMessage);
                    form.val("showDataProviderForm",data.provider);
                }
            });
        }
        //添加采购药品，添加到purchase_drup_detail
        function openAdd() {
            var checkStatus = table.checkStatus('drugMessageTableId');
            //获取选中信息
            var purchaseId = id;
            var drugMessages = new Array();
            var provider = new Array();
            $.each(checkStatus.data,function(index,item) {
                drugMessages.push(item.drugMessage);
                provider.push(item.providerId);
            })
            if(checkStatus.data.length==0){
                layer.msg("请选择要添加的药品");
                return;
            }
            var formData = new FormData();
            formData.append("drugMessageStr",JSON.stringify(drugMessages));
            formData.append("providerId",provider);
            formData.append("purchaseId",purchaseId);
            $.ajax({
                url:"/addPurchaseDrupDetail",
                data:formData,
                type:"post",
                dataType:"json",
                async:false,
                contentType:false,
                processData:false,
                success:function(data) {
                    layer.msg(data.msg);
                    if(data.code==200){
                        //延时
                        setTimeout(function() {
                            window.history.back();
                        },1000);

                    }
                }
            })

        }
        //加载下拉框
        function select(item,url,dataNum) {
            $.get(url,function(data) {
                var html = "<option value='0'>请选择</option>";
                $.each(data.data,function(index,item) {
                    if(item.dataNum===dataNum){
                        html += "<option selected value='"+item.dataNum+"'>"+item.dataName+"</option>"
                    }else {
                        html += "<option value='"+item.dataNum+"'>"+item.dataName+"</option>"
                    }
                })
                item.empty();
                item.append(html);
                // $("#purchaseState").html(html);
                form.render();
            })
        }
        function selectDrugCategory(item,url) {
            $.get(url,function(data) {
                var html = "<option value='0'>请选择药品类别</option>";
                $.each(data,function(index,item) {
                    html += "<option value='"+item.id+"'>"+item.category+"</option>"
                })
                item.empty();
                item.append(html);
                // $("#purchaseState").html(html);
                form.render();
            })
        }
    })
</script>
</body>